package com.vhall.component.controller.rbac;


import com.vhall.component.controller.rbac.facade.RbacGroupFacade;
import com.vhall.component.entity.rbac.vo.*;
import com.vhall.component.framework.common.annotation.VhallComponent;
import com.vhall.component.plugin.common.annotation.VssTokenAuth;
import com.vhall.component.service.rbac.RbacGroupAccessService;
import com.vhall.component.service.rbac.RbacGroupService;
import com.vhall.component.service.rbac.RbacUserGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;


/**
 * @author dalong
 * @date 2021-05-11 18:12
 */
@Api(tags = "RbacGroupController", value = "权限分组")
@Slf4j
@VhallComponent
@VssTokenAuth
public class RbacGroupController implements RbacGroupFacade {

    @Autowired
    private RbacGroupService groupService;

    @Autowired
    private RbacGroupAccessService groupAccessService;

    @Autowired
    private RbacUserGroupService userGroupService;


    @ApiOperation("创建组")
    @RequestMapping(value = "create", method = {RequestMethod.POST})
    @Override
    public GroupVO create(@Validated GroupCreateReqVO reqVO) {
        // token check
        return groupService.create(reqVO);
    }

    @ApiOperation("修改组")
    @Override
    public Boolean update(@Validated GroupUpdateReqVO reqVO) {
        return groupService.update(reqVO);
    }

    @ApiOperation("删除组")
    @Override
    public Boolean delete(@Validated GroupDeleteReqVO reqVO) {
        return groupService.delete(reqVO);
    }

    @ApiOperation("通过应用id获取组列表")
    @Override
    public List<GroupVO> getListByApp(@Validated GroupListReqVO reqVO) {
        return groupService.getAppList(reqVO.getAppId());
    }

    @ApiOperation("增加组权限")
    @Override
    public boolean addAccess(@Validated GroupAddAccessReqVO reqVO) {
        return groupAccessService.addGroupAccess(reqVO);
    }

    @ApiOperation("删除组权限")
    @Override
    public boolean deleteAccess(@Validated GroupDeleteAccessReqVO reqVO) {
        return groupAccessService.deleteGroupAccess(reqVO);
    }

    @ApiOperation("增加用户到指定组")
    @Override
    public boolean addUser(@Validated GroupAddUserReqVO reqVO) {
        return userGroupService.addUser(reqVO);
    }

    @ApiOperation("删除组用户")
    @Override
    public boolean deleteUser(@Validated GroupDeleteUserReqVO reqVO) {
        return userGroupService.deleteUser(reqVO);
    }

    @ApiOperation("获取组权限")
    @Override
    public List<GroupInfoRspVO> info(@Validated GroupInfoReqVO reqVO) {
        return groupService.getListWithAccess(reqVO);
    }
}
